package top.aicey.ai.sparring.controller;

import lombok.extern.slf4j.Slf4j;
import top.aicey.ai.sparring.common.utils.BaseResponseUtil;
import top.aicey.ai.sparring.dto.enums.AliAIAgentCallbackEventEnum;
import top.aicey.ai.sparring.dto.model.BaseResponse;
import top.aicey.ai.sparring.dto.req.AliAIAgentCallback;
import top.aicey.ai.sparring.handler.CallbackEventDispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v3/ai/ali/agent")
@Slf4j
public class AliAgentCallbackController {


    @Autowired
    private CallbackEventDispatcher callbackEventDispatcher;

    /**
     * 记录用户输入日志
     *
     * @param
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/callback")
    public BaseResponse callback(@RequestBody AliAIAgentCallback callback) {

        log.info("ai ali agent receive event:{}",callback);
        // 异常终止情况下才处理 其他情况只打印日志
        if (AliAIAgentCallbackEventEnum.agent_stop.equals(callback.getEvent())){
            callbackEventDispatcher.publisher(callback);
        }
        return BaseResponseUtil.buildSuccessResponse();
    }




}

